<?php
include 'user_detail_lib.php';

if ($s_Action == 'insert') {
    
}
else if ($s_Action == 'update') {
    $db_query  = db_get_query($a_tablecolumns_namhoa_user_dear) . " where dearid = '$f_dearid' limit 1";
    $db_result = db_query($db_conn, $db_query);
    
    if (!($d_user_class = db_fetch($db_result))) { raise_error('Kiểm tra lại thông tin người thân!'); }
}
?>
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
    <h3>Thông Tin Người Thân</h3>
</div>
<form id="dear-profile" class="horizontal-form" action="user_detail_execute.php?action=<?=$s_Action?>-dears&userid=<?=$f_userid?>&dearid=<?=$f_dearid?>" method="post">
    <div class="modal-body">
        <div class="portlet-body">
            <div class="alert alert-error hide">
                <button class="close" data-dismiss="alert"></button>
                Kiểm tra lại thông tin bên dưới.
            </div>
            <div class="row-fluid">
                <div class="span4">
                    <div class="control-group">
                        <label class="control-label">Mối Quan Hệ</label>
                        <div class="controls">
                            <select name="relationship" class="m-wrap span12" >
                                <?php foreach ($a_MoiQuanHe as $v_key => $v_value) { ?>
                                    <option value="<?= $v_key ?>"><?= $v_value ?></option>
                                <?php } ?>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="span4">
                    <div class="control-group">
                        <label for="saint" class="control-label">Tên Thánh</label>
                        <div class="controls">
                            <input type="text" value="<?=$d_user_class->saint?>" placeholder="Giuse" class="m-wrap span12" name="saint" id="saint">
                        </div>
                    </div>
                </div>
                <div class="span4">
                    <div class="control-group">
                        <label for="dearname" class="control-label">Họ và Tên</label>
                        <div class="controls">
                            <input type="text" value="<?=$d_user_class->dearname?>" placeholder="Nguyễn Văn A" class="m-wrap span12" name="dearname" id="dearname">
                        </div>
                    </div>
                </div>
            </div>
            <div class="row-fluid">
                <div class="span6">
                    <div class="control-group">
                        <label for="mobile" class="control-label">ĐTDĐ</label>
                        <div class="controls">
                            <input type="text" value="<?=$d_user_class->mobile?>" placeholder="093 123 456" class="m-wrap span12" name="mobile" id="mobile">
                        </div>
                    </div>
                </div>
                <div class="span6">
                    <div class="control-group">
                        <label for="phone" class="control-label">ĐT Nhà</label>
                        <div class="controls">
                            <input type="text" value="<?=$d_user_class->phone?>" placeholder="39 123 456" class="m-wrap span12" name="phone" id="phone">
                        </div>
                    </div>
                </div>
            </div>
            <div class="row-fluid">
                <div class="span12">
                    <div class="control-group">
                        <label for="address" class="control-label">Địa Chỉ</label>
                        <div class="controls">
                            <input type="text" value="<?=$d_user_class->address?>" name="address" id="address" class="m-wrap span12" placeholder="123 Tên Đường, Phường, Quận" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <button type="button" data-dismiss="modal" class="btn">Thoát</button>
        <button class="btn blue" type="submit"><i class="icon-ok"></i> <?=$s_Action == 'insert' ? 'Thêm' : 'Lưu'?></button>
    </div>
</form>

<script type="text/javascript">
    var handleValidation_dears = function() {

        var frm_dear_profile = $('#dear-profile');
        var err_dear_profile = $('.alert-error', frm_dear_profile);

        frm_dear_profile.validate({
            errorElement: 'span', //default input error message container
            errorClass: 'help-inline', // default input error message class
            focusInvalid: false, // do not focus the last invalid input
            ignore: "",
            rules: {
                dearname: {
                    minlength: 10,
                    required: true
                }
            },
            messages: {
                dearname: {
                    minlength: 'Tối thiểu 10 ký tự',
                    required: 'Bắt buộc nhập'
                }
            },
            invalidHandler: function (event, validator) { //display error alert on form submit              
                err_dear_profile.show();
                App.scrollTo(err_dear_profile, -200);
            },
            highlight: function (element) { // hightlight error inputs
                $(element)
                .closest('.help-inline').removeClass('ok'); // display OK icon
                $(element)
                .closest('.control-group').removeClass('success').addClass('error'); // set error class to the control group
            },
            unhighlight: function (element) { // revert the change done by hightlight
                $(element)
                .closest('.control-group').removeClass('error'); // set error class to the control group
            },
            success: function (label) {
                label
                .closest('.control-group').removeClass('error').addClass('success').end()
                .remove(); // set success class to the control group
            },
            submitHandler: function (form) {
                err_dear_profile.hide();
                form.submit();
            }
        });
    }
    
    handleValidation_dears();
</script>